//
//  DSBaseViewController.m
//  ZhiJiaLianMeng
//
//  Created by AntSailNet on 2018/3/1.
//  Copyright © 2018年 Befiv. All rights reserved.
//

#import "DSBaseViewController.h"
#import <objc/runtime.h>
#import "DSTabBarController.h"
#import "PrefixHeader.pch"

@interface DSBaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation DSBaseViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WHITECOLOR;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    self.navigationController.navigationBar.frame = CGRectMake(0, STATUS_BAR_HEIGHT, SCREEN_WIDTH, 44);
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_org"] forBarMetrics:UIBarMetricsDefault];
 
    
}

#pragma mark -- 加载数据的方法，所有VC加载数据都执行此方法

/**
 执行数据加载
 */
- (void)dataDidLoad{
    
}




- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

#pragma mark -- 滚动到顶部的按钮
- (UIButton *)scrollToTopButton{
    if (!_scrollToTopButton) {
        _scrollToTopButton = [[UIButton alloc]init];
        [self.view addSubview:_scrollToTopButton];
        _scrollToTopButton.hidden = YES;
        _scrollToTopButton.frame = CGRectMake(SCREEN_WIDTH - 63*wl, SCREEN_HEIGHT - 103*hl, 43*wl, 43*wl);
        [_scrollToTopButton setImage:[UIImage imageNamed:@"top_up"] forState:UIControlStateNormal];
        [_scrollToTopButton addTarget:self action:@selector(scrollToTopButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _scrollToTopButton;
}

/**
 点击滚动到顶部的按钮
 
 */
- (void)scrollToTopButtonDidClicked:(UIButton *)sender{
    
}
 
#pragma mark -- model 转字典

/**
 model 转字典

 @param entity 要转换的model
 @return dict
 */
- (NSDictionary *) entityToDictionary:(id)entity{
    
    Class clazz = [entity class];
    u_int count;
    objc_property_t* properties = class_copyPropertyList(clazz, &count);
    NSMutableArray* propertyArray = [NSMutableArray arrayWithCapacity:count];
    NSMutableArray* valueArray = [NSMutableArray arrayWithCapacity:count];
    for (int i = 0; i < count ; i++){
        objc_property_t prop=properties[i];
        const char* propertyName = property_getName(prop);
        [propertyArray addObject:[NSString stringWithCString:propertyName encoding:NSUTF8StringEncoding]];
        id value =  [entity performSelector:NSSelectorFromString([NSString stringWithUTF8String:propertyName])];
        if(value ==nil)
            [valueArray addObject:[NSNull null]];
        else {
            [valueArray addObject:value];
        }
    }

    free(properties);
    NSDictionary* returnDic = [NSDictionary dictionaryWithObjects:valueArray forKeys:propertyArray];
   
    return returnDic;
}

#pragma mark -- 数组变成json字符串
- (NSString *)getJsonStringWithArray:(NSArray *)array{
    NSData *tempData = [NSJSONSerialization  dataWithJSONObject:array options:NSJSONWritingPrettyPrinted  error:nil];
    NSString *json = [[NSString  alloc]initWithData:tempData encoding:NSUTF8StringEncoding];
    json = [json stringByReplacingOccurrencesOfString:@"\n" withString:@""]; // 去掉换行
  //  json = [json stringByReplacingOccurrencesOfString:@"\/" withString:@""];
    json = [json stringByReplacingOccurrencesOfString:@" " withString:@""];
    return json;
}


#pragma mark --   字典转字符串方法

/**
 字典 ===>字符串
 
 */
-(NSString *)convertToJsonData:(NSDictionary *)dict
{
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    if (!jsonData) {
       
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    NSRange range = {0,jsonString.length};
    //去掉字符串中的空格
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    //去掉字符串中的换行符
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    return mutStr;
}



 


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
